/* UTF8 Encoding */
/*-----------------------------------------------------------------------
|                            FILE DESCRIPTION                           |
-----------------------------------------------------------------------*/
/*----------------------------------------------------------------------
  - File name     : sCRC.h
  - Author        : liuzhihua (liuzhihuawy@163.com)
  - Update date   : 2024.06.8
  - Brief         : crc calculate
  - Version       : v0.1
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               UPDATE NOTE                             |
-----------------------------------------------------------------------*/
/**
  * Update note:
  * ------------   ---------------   ----------------------------------
  *     Date            Author                      Note
  * ------------   ---------------   ----------------------------------
  *  2024.03.15       liuzhihua                  Create file   
  *  2024.03.15       liuzhihua                    rename 
       
***/

#ifndef __SCRC_H
#define __SCRC_H

/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include <stdint.h>

#ifdef  __cplusplus
    extern "C" {
#endif
/*-----------------------------------------------------------------------
|                                DEFINES                                |
-----------------------------------------------------------------------*/

typedef struct crc_config_struct
{
    uint32_t initialValue;
    uint32_t polynomial;
    uint32_t xorOutput;
    uint8_t width;
    uint8_t invertInput;
    uint8_t invertOutput;
}crc_config_t;

#define crc_config_create(Width, Polynomial, InitialValue, XorOutput, InvertInput, InvertOutput) \
{                                                                                                \
  .initialValue = InitialValue,                                                                  \
  .polynomial = Polynomial,                                                                      \
  .xorOutput = XorOutput,                                                                        \
  .width = Width,                                                                                \
  .invertInput = InvertInput,                                                                    \
  .invertOutput = InvertOutput                                                                   \
}


extern const crc_config_t CRC_CFG_4_ITU          ;
extern const crc_config_t CRC_CFG_5_EPC          ;
extern const crc_config_t CRC_CFG_5_ITU          ;
extern const crc_config_t CRC_CFG_5_USB          ;
extern const crc_config_t CRC_CFG_6_ITU          ;
extern const crc_config_t CRC_CFG_7_MMC          ;
extern const crc_config_t CRC_CFG_8              ;
extern const crc_config_t CRC_CFG_8_ITU          ;
extern const crc_config_t CRC_CFG_8_ROHC         ;
extern const crc_config_t CRC_CFG_8_MAXIM        ;
extern const crc_config_t CRC_CFG_16_IBM         ;
extern const crc_config_t CRC_CFG_16_MAXIM       ;
extern const crc_config_t CRC_CFG_16_USB         ;
extern const crc_config_t CRC_CFG_16_MODBUS      ;
extern const crc_config_t CRC_CFG_16_CCITT       ;
extern const crc_config_t CRC_CFG_16_CCITT_FALSE ;
extern const crc_config_t CRC_CFG_16_X25         ;
extern const crc_config_t CRC_CFG_16_XMODEM      ;
extern const crc_config_t CRC_CFG_16_DNP         ;
extern const crc_config_t CRC_CFG_32             ;
extern const crc_config_t CRC_CFG_32_MPEG2       ;

#define CRC_CALC(crc_config_, data_, byteLen_) crc_calculate(crc_config_, (crc_config_)->initialValue, data_, byteLen_)

/*-----------------------------------------------------------------------
|                                  API                                  |
-----------------------------------------------------------------------*/
uint32_t crc_invert_bits(uint32_t data, uint8_t bits);
uint32_t crc_calculate(const crc_config_t *cfg, uint32_t crc_init, const void *pdata, uint32_t byteLen);

#ifdef __cplusplus
	}
#endif
#endif
